package tech.swh.ssm.controller;

import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import tech.swh.ssm.entity.Backend;
import tech.swh.ssm.entity.Dev;
import tech.swh.ssm.service.BackService;
import tech.swh.ssm.service.DevService;


@Controller
public class IndexController {
	
	@Autowired
	private BackService backService;
	@Autowired
	private DevService devService;

	@RequestMapping(value = {"/login.html",""})
	public String tologin() {
		return "login";
	}

	@RequestMapping(value = "/login.action",method = RequestMethod.POST)
	public String backlogin(String Username,String Password,HttpSession session,Model model) {
		Backend back = backService.getBackend(Username, Password);
		if (back!=null) {
			session.setAttribute("user",back);
			return "index";
		}
		model.addAttribute("msg", "账号或密码错误!");
		return "login";
	}
	
	@RequestMapping(value = {"/toDevlogin.html","dev"})
	public String toDevlogin() {
		return "dev_login";
	}
	
	@RequestMapping(value = "devlogin.action",method = RequestMethod.POST)
	public String devlogin(String Username,String Password,HttpSession session,Model model) {
		System.err.println(Username+Password);
		Dev dev = devService.getDev(Username, Password);
		if (dev!=null) {
			session.setAttribute("user",dev);
			return "redirect:sys/dev/goDevApplist.html";
		}
		model.addAttribute("msg", "账号或密码错误!");
		return "dev_login";
	}
	
}
